%{
if (_items != null) {
  // wrap raw Lists with the Paginator class
  if (!(_items instanceof play.modules.paginate.Paginator)) {
    if (_items instanceof List || _items instanceof Set || _items instanceof Map) {
        _items = new play.modules.paginate.ValuePaginator(_items);
    } 
  }
  idx = _items.firstRowIndex + 1;
  rowCount = _items.rowCount;  
  for (_r in _items.currentPage) {
    layoutData = nil;
    if (play.version.startsWith("1.0")) {
        layoutData = play.templates.Template.layoutData.get(); 
    } else { // play 1.1 (and hopefully later?)
        layoutData = play.templates.BaseTemplate.layoutData.get(); 
    }
    layoutData.put(_as, _r);
    layoutData.put(_as+'_index', idx);
    layoutData.put(_as+'_isLast', idx == rowCount);
    layoutData.put(_as+'_isFirst', idx == 1);
    layoutData.put(_as+'_parity', idx % 2 == 0 ? 'even' : 'odd');
    idx++;
%}
	#{doBody/}
%{
  }
  if (rowCount == 0) {
    play.templates.TagContext.parent().data.put('_executeNextElse', true);
  }else{
    play.templates.TagContext.parent().data.put('_executeNextElse', false);
  }
}
%}
